Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Web.Configuration
Imports facebook.web
Imports System.Collections.Generic
Imports System.Text

Namespace FBMLSample
	Public Class BasePage
		Inherits Page
		Public ReadOnly Property FeedTemplate1() As Long
			Get
				Return Long.Parse(WebConfigurationManager.AppSettings("TemplateID1"))
			End Get
		End Property
		Public ReadOnly Property FeedTemplate2() As Long
			Get
				Return Long.Parse(WebConfigurationManager.AppSettings("TemplateID2"))
			End Get
		End Property

        Public Function getMoods() As Dictionary(Of String, String)
            Dim moods = New Dictionary(Of String, String)
            moods.Add("Happy", ":)")
            moods.Add("Indifferent", ":|")
            moods.Add("Cool", "B-|")
            moods.Add("Emo", "//.-")
            moods.Add("Surprised", "=O")
            moods.Add("Laughing", "XD")
            moods.Add("Vampire", ": [")
            moods.Add("Evil", ">:|")

            Return moods
        End Function

		Public Function getOtherMoods() As Dictionary(Of String, String)
            Dim otherMoods = New Dictionary(Of String, String)
            otherMoods.Add("Kiss", ":-*")
            otherMoods.Add("Wink", ";]")
            otherMoods.Add("Confused", ":@")
            otherMoods.Add("Tear", ":'-)")
            otherMoods.Add("Tongue", ":P")
            otherMoods.Add("Bite", ":-K")

            Return otherMoods
		End Function
		Public Function BuildEmoticonGrid(ByVal moods As Dictionary(Of String, String), ByVal callback As String, ByVal suffix As String) As String
			Return BuildEmoticonGrid(moods, callback, suffix, True)
		End Function
		Public Function BuildEmoticonGrid(ByVal moods As Dictionary(Of String, String), ByVal callback As String, ByVal suffix As String, ByVal useFinalFunction As Boolean) As String
			Dim ret = New StringBuilder()
			ret.Append("<div class=""table""><div class=""row"">")
			For i As Integer = 0 To moods.Count - 1
				Dim js = String.Format("final('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", FeedTemplate1, callback & "images", "http://apps.new.facebook.com/" & suffix, callback, moods.ElementAt(i).Key, moods.ElementAt(i).Value, i)
				If (Not useFinalFunction) Then
					js = String.Format("select('{0}','{1}','{2}')", moods.ElementAt(i).Key, moods.ElementAt(i).Value, i)
				End If
				If i > 0 AndAlso i Mod 3 = 0 Then
					ret.Append("</div><div class=""row"">")
				End If
				ret.Append(String.Format("<div onclick=""{0}"" onmouseover=""over('{3}')"" onmouseout=""out('{3}')"" class=""box"" id=""sm_{3}""><div class=""smiley"">{2}</div><div id=""smt_{3}"" class=""title"">{1}</div></div>", js, moods.ElementAt(i).Key, moods.ElementAt(i).Value, i))
			Next i
			ret.Append("</div></div>")
			Return ret.ToString()
		End Function

	End Class
End Namespace
